Support more callable converters in the attrs plugin#21442
Open
filbranden wants to merge 1 commit intopython:masterfrom
Open
Support more callable converters in the attrs plugin#21442filbranden wants to merge 1 commit intopython:masterfrom
filbranden wants to merge 1 commit intopython:masterfrom
Conversation
The attrs plugin only recognized converters that were named functions, types, or lambdas. Extend it to also accept: - Calls returning a callable, e.g. `converter=make_converter(arg)` — the long-standing request in python#15736. Includes chained calls and overloaded callees (such as `attrs.converters.pipe`/`default_if_none`). - Variables annotated with a callable type. The init parameter type is still derived from the first positional parameter of the wrapped callable, so existing diagnostics for converters with the wrong signature continue to apply. Fixes python#15736. This was authored with the help of Claude Code.
5 tasks
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: core (https://github.com/home-assistant/core)
+ homeassistant/helpers/entity_registry.py:223: error: Unused "type: ignore" comment [unused-ignore]
|
Author
After a new release of mypy that includes this change, I'm glad to follow up with a PR to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The attrs plugin only recognized converters that were named functions, types, or lambdas. Extend it to also accept:
converter=make_converter(arg)— the long-standing request in Unsupported converter, only named functions, types and lambdas are currently supported with higher-order function #15736. Includes chained calls and overloaded callees (such asattrs.converters.pipe/default_if_none).The init parameter type is still derived from the first positional parameter of the wrapped callable, so existing diagnostics for converters with the wrong signature continue to apply.
Fixes #15736.
This was authored with the help of Claude Code.
Checklist:
This is a follow up to #21408, with a narrower scope of only supporting more callable converters and not adding support for the
Converterclass, which can be done in a later follow up or further revision of #21408 once this PR is merged.